const App = getApp();
const wxParse = require('../../wxParse/wxParse.js')
const qingxilist = require('../../utils/qingxilist.js')
const siteinfo = require('../../siteinfo.js')

Page({

  data: {
    id: "",
    // 页面参数
    qingxilist: qingxilist,
    options: {},
    // 页面元素
    scrollTop: 0,
    index: 0,
    detail: {},
    tuResult: true, //检测一下是不是有没有图片未传完
    LouCengGaoDu: [],
    GuanCai: [],
    GuanCaiChangDu: [],
    ChaoBiaoDaoHu: '',
    DongBiaoWeiZhi: [],// 栋表位置
    DongBiaoShiNei: [],// 栋表室内
    DongBiaoShiWai: [],// 栋表室外
    HuBiaoWeiZhi: [],// 
    HuBiaoGeShu: [],// 
    ShuiChiYong: [],
    ShuiChiZhong: [],
    ShuiChiZhongGeShu: [],
    GongShuiFangShi: [],
    QingXiFangShi: [],
    ShuiZhiJianCeBaoGao: [],
    GuanLiRenYuan: [],
    XianChangZhaoPian: [],
    GongZuoZhaoPian: [],
    WenTiZhaoPian: [],
    qingkong: '',
    $data: {},
    ChaoBiaoDaoList: [
      {
        value: '抄表未到栋/户'
      },
      {
        value: '抄表到栋'
      },
      {
        value: '抄表到户'
      }
    ],
    LouCengGaoDuList: [
      {
        value: '7层及以下',
        checked: false
      },
      {
        value: '8~15层',
        checked: false
      },
      {
        value: '16层及以上',
        checked: false
      }
    ],
    GuanCaiList: [
      {
        value: '灰口铸铁管',
        dataname: 'huikouchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '球墨铸铁管',
        dataname: 'qiumochangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '镀锌钢管',
        dataname: 'duxinchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '钢塑管',
        dataname: 'gangshuchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '铝塑管',
        dataname: 'lvsuochangdu',
        datavalue: '',
        checked: false
      },
      {
        value: 'PVC管',
        dataname: 'pvcchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: 'PPR',
        dataname: 'pprchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: 'PE管',
        dataname: 'pechangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '薄壁不锈钢钢管316',
        dataname: '316changdu',
        datavalue: '',
        checked: false
      },
      {
        value: '薄壁不锈钢钢管304',
        dataname: '304changdu',
        datavalue: '',
        checked: false
      },
      {
        value: '内衬不锈钢',
        dataname: 'neichenchangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '聚四氟乙烯管',
        dataname: 'jusichangdu',
        datavalue: '',
        checked: false
      },
      {
        value: '其他',
        dataname: 'guancaiqitachangdu',
        datavalue: '',
        checked: false
      }
    ],
    DongBiaoWeiZhiList: [
      {
        value: "室外",
        checked: false,
        child: [
          {
            value: "地面",
            checked: false
          },
          {
            value: "水表井",
            checked: false
          },
          {
            value: "楼顶",
            checked: false
          },
          {
            value: "其他",
            checked: false
          }
        ]
      },
      {
        value: "室内",
        checked: false,
        child: [
          {
            value: "地下",
            checked: false
          },
          {
            value: "一楼",
            checked: false
          },
          {
            value: "楼顶",
            checked: false
          },
          {
            value: "其他",
            checked: false
          }
        ]
      }
    ],
    HuBiaoWeiZhiList: [
      {
        value: '户内',
        dataname: 'huneigeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '管道井',
        dataname: 'guandaojinggeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '楼梯间',
        dataname: 'loutijiangeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '楼顶',
        dataname: 'loudinggeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '一楼室内',
        dataname: 'yiloushineigeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '一楼室外',
        dataname: 'yiloushiwaigeshu',
        datavalue: '',
        checked: false
      },
      {
        value: '其他',
        dataname: 'hubiaoqitageshu',
        datavalue: '',
        checked: false
      }
    ],
    ShuiChiZhuangTai: [
      {
        value: '弃用',
        dataname: 'ShuiChiQiYongShuLiang',
        checked: false
      },
      {
        value: '在用',
        dataname: 'ShuiChiYongShuLiang',
        checked: false
      }
    ],
    YongShuiChi: [
      {
        value: '单独生活',
        dataname: 'shenghuogeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '单独消防',
        dataname: 'xiaofanggeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '生活消防共用',
        dataname: 'zonggong',
        datavalue:'',
        checked: false
      },
      {
        value: '天面',
        dataname: 'tianmiangeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '地下',
        dataname: 'dixiageshu',
        datavalue:'',
        checked: false
      }
    ],
    GongShuiFangShiList: [
      {
        value: '市政直供',
        checked: false
      },
      {
        value: '市政+水泵',
        checked: false
      },
      {
        value: '市政+天面池',
        checked: false
      },
      {
        value: '市政+水泵+天面池',
        checked: false
      },
      {
        value: '市政+地下水池+水泵',
        checked: false
      },
      {
        value: '市政+地下水池+水泵+天面池',
        checked: false
      },
    ],
    QingXiFangShiList: [
      {
        value: '不清洗',
        checked: false
      },
      {
        value: '业主自洗',
        checked: false
      },
      {
        value: '其他有资质单位清洗',
        checked: false
      },
      {
        value: '一年清洗2次以上',
        checked: false
      },
      {
        value: '一年清洗2次 ',
        checked: false
      },
      {
        value: '一年清洗1次',
        checked: false
      },
      {
        value: '一年以上清洗1次',
        checked: false
      },
      {
        value: '有CMA认证的水质检测报告',
        checked: false
      },
      {
        value: '有非CMA认证的水质检测报告',
        checked: false
      },
      {
        value: '无水质检测报告',
        checked: false
      }
    ],
    YouWuShuiZhi: [
      {
        value: '有',
        checked: false
      },
      {
        value: '无',
        checked: false
      }
    ],
    GuanLiRenYuanList: [
      {
        value: '专人管理',
        checked: false
      },
      {
        value: '无人管理',
        checked: false
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    console.log("openid", wx.getStorageSync('openid'))
    this.setData({
      id: options.id
    })
    this.getDetail(options.id)
  },
  getDetail(e) {
    let _this = this
    wx.request({
      url: App.api_test + 'GetChengZhongCunFuBiaoInfo',
      header: {
        'content-type': 'application/JSON',
      },
      method: 'POST',
      data: {
        id: e
      },
      success(res) {
        console.log('城中村附件详情', res)
        // 楼层高度多选
        var arr = res.data.LouCengGaoDu ? res.data.LouCengGaoDu.split(',') : [];
        var arr2 = []
        for (let i in _this.data.LouCengGaoDuList) {
          for (let j in arr) {
            if (_this.data.LouCengGaoDuList[i].value == arr[j]) {
              arr2[i] = parseInt(i)
            }
          }
        }
        // 管材多选
        var arrGuanCai = res.data.GuanCai ? res.data.GuanCai.split(',') : [];
        var arr3 = []
        for (let i in _this.data.GuanCaiList) {
          for (let j in arrGuanCai) {
            if (_this.data.GuanCaiList[i].value == arrGuanCai[j]) {
              arr3[i] = parseInt(i)
            }
          }
        }
        // 管材长度处理
        var jsonArr = res.data.GuanCaiChangDu ? JSON.parse(res.data.GuanCaiChangDu) : []
        console.log("jsonArr", jsonArr)
        _this.data.GuanCaiList.forEach(function (e, i) {
          jsonArr.forEach(function (item, index) {
            let key = item.name
            let value = item.value
            if (e.dataname == key) {
              e.datavalue = value
            }
          })
        })
        _this.setData({
          GuanCaiList: _this.data.GuanCaiList
        })

        // 户表多选
        var arrHuBiao = res.data.HuBiaoWeiZhi ? res.data.HuBiaoWeiZhi.split(',') : [];
        var arr4 = []
        for (let i in _this.data.HuBiaoWeiZhiList) {
          for (let j in arrHuBiao) {
            if (_this.data.HuBiaoWeiZhiList[i].value == arrHuBiao[j]) {
              arr4[i] = parseInt(i)
            }
          }
        }
        // 户表数量处理
        var jsonArrHuBiao = res.data.HuBiaoGeShu ? JSON.parse(res.data.HuBiaoGeShu) : []
        _this.data.HuBiaoWeiZhiList.forEach(function (e, i) {
          jsonArrHuBiao.forEach(function (item, index) {
            let key = item.name
            let value = item.value
            if (e.dataname == key) {
              e.datavalue = value
            }
          })
        })
        _this.setData({
          HuBiaoWeiZhiList: _this.data.HuBiaoWeiZhiList
        })
        // 水池多选
        var arrShuiChi = res.data.ShuiChiYong ? res.data.ShuiChiYong.split(',') : [];
        var arr5 = []
        for (let i in _this.data.ShuiChiZhuangTai) {
          for (let j in arrShuiChi) {
            if (_this.data.ShuiChiZhuangTai[i].value == arrShuiChi[j]) {
              arr5[i] = parseInt(i)
            }
          }
        }
        // 在用水池多选
        var arrShuiChiZhong = res.data.ShuiChiZhong ? res.data.ShuiChiZhong.split(',') : [];
        var arr6 = []
        for (let i in _this.data.YongShuiChi) {
          for (let j in arrShuiChiZhong) {
            if (_this.data.YongShuiChi[i].value == arrShuiChiZhong[j]) {
              arr6[i] = parseInt(i)
            }
          }
        }
        // 在用水池数量处理
        var jsonArrShuiChiZhong = res.data.ShuiChiZhongGeShu ? JSON.parse(res.data.ShuiChiZhongGeShu) : []
        _this.data.YongShuiChi.forEach(function (e, i) {
          jsonArrShuiChiZhong.forEach(function (item, index) {
            let key = item.name
            let value = item.value
            if (e.dataname == key) {
              e.datavalue = value
            }
          })
        })
        _this.setData({
          YongShuiChi: _this.data.YongShuiChi
        })

        // 栋表安装位置
        var arrDongBiao = res.data.DongBiaoWeiZhi ? res.data.DongBiaoWeiZhi.split(',') : [];
        var arr7 = []
        for (let i in _this.data.DongBiaoWeiZhiList) {
          for (let j in arrDongBiao) {
            if (_this.data.DongBiaoWeiZhiList[i].value == arrDongBiao[j]) {
              arr7[i] = parseInt(i)
            }
          }
        }
        console.log("栋表安装位置",arr7)
        // 栋表安装位置室内
        var arrDongBiaoShiNei = res.data.DongBiaoShiNei ? res.data.DongBiaoShiNei.split(',') : [];
        var arr8 = []
        var shineiList = []
        for (let i in _this.data.DongBiaoWeiZhiList) {
            if(_this.data.DongBiaoWeiZhiList[i].value=='室内'){
              shineiList=_this.data.DongBiaoWeiZhiList[i].child
            }
        }
        for (let i in shineiList) {
          for (let j in shineiList) {
            if (shineiList[i].value == arrDongBiaoShiNei[j]) {
              arr8[i] = parseInt(i)
            }
          }
        }

        // 栋表安装位置室外
        var arrDongBiaoShiWai = res.data.DongBiaoShiWai ? res.data.DongBiaoShiWai.split(',') : [];
        var arr9 = []
        var shiwaiList = []
        for (let i in _this.data.DongBiaoWeiZhiList) {
            if(_this.data.DongBiaoWeiZhiList[i].value=='室外'){
              shiwaiList=_this.data.DongBiaoWeiZhiList[i].child
            }
        }
        for (let i in shiwaiList) {
          for (let j in shiwaiList) {
            if (shiwaiList[i].value == arrDongBiaoShiWai[j]) {
              arr9[i] = parseInt(i)
            }
          }
        }
        console.log('数据设置值', _this.data.GuanCaiList)
        console.log('管材长度',JSON.parse(res.data.GuanCaiChangDu))
        _this.setData({
          detail: res.data,
          TianBiaoRiQi: res.data.TianBiaoRiQi,
          LouCengGaoDu: arr,
          arr2: arr2,
          arr3: arr3,
          arr4: arr4,
          arr5: arr5,
          arr6: arr6,
          arr7: arr7,
          arr8: arr8,
          arr9: arr9,
          jsonArr: jsonArr,
          jsonArrHuBiao: jsonArrHuBiao,
          jsonArrShuiChiZhong: jsonArrShuiChiZhong,
          GuanCai: res.data.GuanCai?res.data.GuanCai.split(','):[],
          GuanCaiChangDu:res.data.GuanCaiChangDu?JSON.parse(res.data.GuanCaiChangDu):[],
          HuBiaoGeShu:res.data.HuBiaoGeShu?JSON.parse(res.data.HuBiaoGeShu):[],
          ShuiChiZhongGeShu:res.data.ShuiChiZhongGeShu?JSON.parse(res.data.ShuiChiZhongGeShu):[],
          DongBiaoWeiZhi:res.data.DongBiaoWeiZhi?res.data.DongBiaoWeiZhi.split(',') : [],
          DongBiaoShiNei:res.data.DongBiaoShiNei?res.data.DongBiaoShiNei.split(',') : [],
          DongBiaoShiWai:res.data.DongBiaoShiWai?res.data.DongBiaoShiWai.split(',') : [],
          HuBiaoWeiZhi:res.data.HuBiaoWeiZhi?res.data.HuBiaoWeiZhi.split(',') : [],
          ShuiChiYong:res.data.ShuiChiYong?res.data.ShuiChiYong.split(',') : [],
          ShuiChiZhong:res.data.ShuiChiZhong?res.data.ShuiChiZhong.split(',') : [],
          XianChangZhaoPian: res.XianChangZhaoPian ? res.XianChangZhaoPian.split(',') : [],
          GongZuoZhaoPian: res.GongZuoZhaoPian ? res.GongZuoZhaoPian.split(',') : [],
          WenTiZhaoPian: res.WenTiZhaoPian ? res.WenTiZhaoPian.split(',') : [],
        })
        console.log('楼层高度', _this.data.arr3)
      },
      fail(res) {
        console.log('城中村附件详情异常', res);
      }
    })
    return
    App._get("GetChengZhongCunuXunChaInfo", { id: e, userId: wx.getStorageSync('user_id') ? wx.getStorageSync('user_id') : '' }, (res) => {
      console.log(res)
      _this.setData({
        detail: res.data
      })
    })
  },
 

  formSubmit(e) {
    console.log('提交')
    var _this = this
    let data = {
      ...e.detail.value,
    }
    try {
      if (_this.data.loading) {
        return
      }
      _this.setData({
        loading: true
      })
      data.id = this.data.id
      data.TianBiaoRiQi = this.data.TianBiaoRiQi
      data.LouCengGaoDu = this.data.LouCengGaoDu.join(',')
      data.GuanCai = this.data.GuanCai.join(',')
      data.GuanCaiChangDu = JSON.stringify(this.data.GuanCaiChangDu)
      data.DongBiaoWeiZhi = this.data.DongBiaoWeiZhi.join(',')
      data.DongBiaoShiNei = this.data.DongBiaoShiNei.join(',')
      data.DongBiaoShiWai = this.data.DongBiaoShiWai.join(',')
      data.HuBiaoWeiZhi = this.data.HuBiaoWeiZhi.join(',')
      data.HuBiaoGeShu = JSON.stringify(this.data.HuBiaoGeShu)
      data.ShuiChiYong = this.data.ShuiChiYong.join(',')
      data.ShuiChiZhong = this.data.ShuiChiZhong.join(',')
      data.ShuiChiZhongGeShu = JSON.stringify(this.data.ShuiChiZhongGeShu)
      data.XianChangZhaoPian = this.data.XianChangZhaoPian.join(',')
      data.GongZuoZhaoPian = this.data.GongZuoZhaoPian.join(",")
      data.WenTiZhaoPian = this.data.WenTiZhaoPian.join(",")
    } catch (e) {
      wx.showModal({
        cancelColor: 'cancelColor',
        showCancel: false,
        title: '错误',
        content: 'e'
      })
    }
    console.log("提交数据", data)
    
    wx.request({
      url: App.api_test + (e.detail.target.dataset.xingwei == "tijiao"?'SaveChengZhongCunFuBiao':'ZanCunChengZhongCunFuBiao'),
      header: {
        'content-type': 'application/JSON',
      },
      method: 'POST',
      data: {
        fuBiaoEntity: data,
        openId: wx.getStorageSync('openid'),
        userId: wx.getStorageSync('user_id')
      },
      success(res) {
        console.log('暂存成功', res)
        wx.showModal({
          title: res.data,
          showCancel: false,
          complete: () => {
            // wx.navigateBack()
            _this.setData({
              loading: false
            })
          }
        })
      },
      fail(res) {
        console.log(res);
      }
    })
    return
    wx.showLoading({
      title: '提交中',
    })
    App._post_form(e.detail.target.dataset.xingwei == "tijiao" ? 'ChengZhongCunShenHe' : 'SaveChengZhongCunXunCha', data, (res) => {
      this.setData(_this.data.$data)
      wx.showModal({
        title: res,
        showCancel: false,
        complete: () => {
          // wx.navigateBack()
          _this.setData({
            loading: false
          })
        }
      })
    }, () => { }, () => {
      wx.hideLoading()
    })
  },

  radioChangeLouCengGaoDu(e) {
    console.log('楼层高度1', e.detail.value)
    this.setData({
      LouCengGaoDu: e.detail.value
    })
    console.log('楼层高度2', e.detail.value)
  },
  radioChangeGuanCai(e) {
    console.log('管材', e.detail.value)
    this.setData({
      GuanCai: e.detail.value
    })
    console.log('管材', e.detail.value)
  },
  blurGuanCai(e) {
    // console.log(e)
    // console.log('管材长度',e.detail.value)
    // console.log(e.target.dataset.name)
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.GuanCaiChangDu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      GuanCaiChangDu: list
    })
  },
  radioChangeChaoBiao(e) {
    this.setData({
      ChaoBiaoDaoHu: e.detail.value
    })
  },
  radioChangeDongBiao(e) {
    this.setData({
      DongBiaoWeiZhi: e.detail.value
    })
    console.log('栋表位置', e.detail.value)
  },
  radioChangeDongBiaoShiNei(e) {
    this.setData({
      DongBiaoShiNei: e.detail.value
    })
    console.log('栋表室内', e.detail.value)
  },
  radioChangeDongBiaoShiWai(e) {
    this.setData({
      DongBiaoShiWai: e.detail.value
    })
    console.log('栋表室外', e.detail.value)
  },
  radioChangeHuBiao(e) {
    this.setData({
      HuBiaoWeiZhi: e.detail.value
    })
    console.log('户表位置', e.detail.value)
  },
  // 户表长度
  blurHuBiao(e) {
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.HuBiaoGeShu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      HuBiaoGeShu: list
    })
    console.log("户表个数", this.data.HuBiaoGeShu)
  },
  radioChangeShuiChi(e) {
    this.setData({
      ShuiChiYong: e.detail.value
    })
    console.log('水池用', e.detail.value)
  },
  radioChangeShuiChiZhong(e) {
    this.setData({
      ShuiChiZhong: e.detail.value
    })
    console.log('水池中', e.detail.value)
  },
  // 水池中
  bindShuiChiZhong(e) {
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.ShuiChiZhongGeShu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      ShuiChiZhongGeShu: list
    })
    console.log("水池中个数", this.data.ShuiChiZhongGeShu)
  },
  radioChangeGongShui(e) {
    this.setData({
      ShuiChiZhong: e.detail.value
    })
    console.log('供水方式', e.detail.value)
  },
  radioChangeQingXi(e) {
    this.setData({
      ShuiChiZhong: e.detail.value
    })
    console.log('清洗方式', e.detail.value)
  },
  radioChangeShuiZhi(e) {
    this.setData({
      ShuiZhiJianCeBaoGao: e.detail.value
    })
    console.log('水质报告', e.detail.value)
  },
  radioChangeGuanli(e) {
    this.setData({
      GuanLiRenYuan: e.detail.value
    })
    console.log('管理人员', e.detail.value)
  },
  bindDateChange(e) { //填表时间
    this.setData({
      TianBiaoRiQi: e.detail.value
    })
  },

  radioChange(e) {
    let _this = this
    if (e.target.dataset.name) {
      let data = {}
      data[e.target.dataset.name] = e.detail.value
      _this.setData(data)
    }
  },
 /**
   * 分享当前页面
   */
  onShareAppMessage() {
    let _this = this;
    return {
      title: _this.data.detail.Name,
      path: `/pages/index/idnex`,
    };
  },

  // 多余代码
  bindDateChangeErGongSheShiQingXiShiJian(e) { //清洗时间
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      ErGongSheShiQingXiShiJian: e.detail.value
    })
  },
  bindDateErGongSheShiJianCeShiJian(e) { // 检测时间
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      ErGongSheShiJianCeShiJian: e.detail.value
    })
  },

  bindErGongSheShiQingXiJiGou(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      bindErGongSheShiQingXiJiGou: e.detail.value,
      index: e.detail.value
    })
  },

  radioChangeJinChuShuiGuanCaiZhi(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      JinChuShuiGuanCaiZhi: e.detail.value
    })
  },
  radioChangeErGongTianMianShuiChiCaiZhi(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      ErGongTianMianShuiChiCaiZhi: e.detail.value
    })
  },
  radioChangeYongZhiYongShuiYiLiXiang(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      YongZhiYongShuiYiLiXiang: e.detail.value
    })
  },
  radioChangeGuanGaiMoShi(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      GuanGaiMoShi: e.detail.value
    })
  },
  radioChangeJieShuiQiJuGuanXiaDanWei(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      JieShuiQiJuGuanXiaDanWei: e.detail.value
    })
  },
  blurLianXiFangShi(e) {
    // if (e.detail.value.length != "11") {
    //   wx.showModal({
    //     showCancel: false,
    //     title: '手机号必须为11位'
    //   })
    // }
  },
  shanchu(e) {
    //  e.target.name
    let _this = this
    console.log(e)
    let arr = []
    arr = arr.concat(_this.data[e.target.dataset.name])
    arr.splice(e.target.dataset.index, 1)
    this.setData(_this.setKeyAndValue(e.target.dataset.name, arr))
  },
  setKeyAndValue(key, value) {
    var obj = {};
    console.log(key)
    obj[key] = value
    console.log(obj)
    return obj
  },
  searchQingkong(e) {
    let _this = this;
    App._get('GetQingXiJiGou', {
      name: e.detail.value
    }, (res) => {
      console.log(res)
      if (res.length === 0) {
        res = [{
          Name: '暂无数据'
        }]
      }
      _this.setData({
        qingkongList: res
      })
    })
  },
  selectQingkong(e) {
    this.setData({
      qingkongList: [],
      ErGongSheShiQingXiJiGou: e.currentTarget.dataset.name
    })
  },
  bindXianChangZhaoPian() {
    let _this = this
    var XianChangZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.XianChangZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            XianChangZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  bindGongZuoZhaoPian() {
    let _this = this
    var GongZuoZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.GongZuoZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            GongZuoZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  bindWenTiZhaoPian() {
    let _this = this
    var WenTiZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.WenTiZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            WenTiZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  shanchu(e) {
    //  e.target.name
    let _this = this
    console.log(e)
    let arr = []
    arr = arr.concat(_this.data[e.target.dataset.name])
    arr.splice(e.target.dataset.index, 1)
    this.setData(_this.setKeyAndValue(e.target.dataset.name, arr))
  },
  setKeyAndValue(key, value) {
    var obj = {};
    console.log(key)
    obj[key] = value
    console.log(obj)
    return obj
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function () {
    // 获取首页数据
    wx.stopPullDownRefresh();
  },
  /**
   * 滚动到底部
   */
  goBottom() {
    var obj = wx.createSelectorQuery();
    obj.selectAll('.container').boundingClientRect(function (rect) {
      wx.pageScrollTo({
        scrollTop: rect[0].height,
        duration: 300
      });
    })
    obj.exec();
  },
  onShareAppMessage() {
    return {
      title: '城中村巡查附件',
      path: "/pages/chengzhongcun_fujian/index"
    };
  },

});